package com.sky.controller.User;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "购物车")

public class shoppingCartcontroller {
    @Autowired
     ShoppingCartService shoppingCartService;
    @PostMapping("/add")
    @ApiOperation("添加到购物车")
    public Result<ShoppingCart> addCart(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        log.info("菜品为{}",shoppingCartDTO);
        shoppingCartService.addCart(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> select()
    {
        List<ShoppingCart> list = shoppingCartService.select();
        return  Result.success(list);
    }
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<ShoppingCart> delete()
    {
        shoppingCartService.delete();
        return  Result.success();
    }
    @PostMapping("/sub")
    @ApiOperation("删除其中的一个菜品")
    public Result<ShoppingCart> deleteById(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        shoppingCartService.deleteById(shoppingCartDTO);
        return  Result.success();
    }
}
